'use strict';

import Vue from 'vue'
import { usingUrl } from './global_variable.js'

/**
 * 用于向后台以POST方法提交FormData数据
 * @param {String}  url
 * @param {Object}  params
 * @return {Promise}
 */

Vue.prototype.$postFd = (url,params) => {
	return new Promise((resolve,reject) => {
		uni.request({
			url:usingUrl + url,
			data:params,
			header:{
				'Content-Type': 'application/x-www-form-urlencoded'
			},
			method:'POST',
			success:res => resolve(res),
			fail:err => reject(err)
		})
	})
};

/**
 * 用于向后台以POST方法以JSON形式提交
 */

Vue.prototype.$postJson = (url,params) => {
	return new Promise((resolve,reject) => {
		uni.request({
			url:usingUrl + url,
			data:params,
			header:{
				'Content-Type': 'application/json'
			},
			methods:'POST',
			success:res => resolve(res),
			fail:err => reject(err)
		})
	})
};

/**
 * 用于向后台以GET方法获取数据
 * @param {String} url
 * @param {Object} params
 * @return {Promise}
 */

Vue.prototype.$get = (url,params) => {
	return new Promise((resolve,reject) => {
		uni.request({
			url: usingUrl + url,
			data: params,
			methods:"GET",
			success:res => resolve(res),
			fail:err => reject(err)
		})
	})
}

